<template>
	<view class="main">
		<u-navbar :is-back="true" title="状态设置" title-color="white" :background="background"></u-navbar>
		<p class="p_text">图文咨询
			<u-switch v-model="TWchecked" @change="checked()" style="float: right;"></u-switch>
		</p>
		<p class="p_text">语音咨询
			<u-switch v-model="WYchecked" @change="checked()" style="float: right;"></u-switch>
		</p>
		<p class="p_text">视频咨询
			<u-switch v-model="SPchecked" @change="checked()" style="float: right;"></u-switch>
		</p>
		<button type="default"></button>
		<u-button type="primary" @click="checkedAll()" style="width: 90%;position: fixed;bottom: 60rpx;left: 5%;">
			一键开启/关闭
		</u-button>
	</view>
</template>

<script>
	export default {
		onLoad() {
			// setTimeout(() => {
			// 	this.$u.route({
			// 		url: '/pages/setting/setting',
			// 		params: {
			// 			name: 'lisa'
			// 		}
			// 	})
			// 	console.debug("aas")
			// }, 2000),
			this.getStatuslist();
		},
		data() {
			return {
				background: {
					backgroundColor: '#00a8ff'
				},
				TWchecked: '',
				WYchecked: '',
				SPchecked: '',
			}
		},
		methods: {
			change(status) {
				console.log(status);
			},
			// 获取接单状态列表 // 没问题
			getStatuslist() {
				this.$apiVipCentre.statuslist()
					.then((res) => {
						if (res.data.data.text_status == "1") {
							this.TWchecked = true;
						} else {
							this.TWchecked = false;
						}
						if (res.data.data.language_status == "1") {
							this.WYchecked = true;
						} else {
							this.WYchecked = false;
						}
						if (res.data.data.video_status == "1") {
							this.SPchecked = true;
						} else {
							this.SPchecked = false;
						}
					}).catch((err) => {
						console.log(err);
					})
			},

			// 接单状态设置
			checked() {
				let text_status = "0";
				let language_status = "0";
				let video_status = "0";
				if (this.TWchecked == true) {
					text_status = "1";
				}
				if (this.WYchecked == true) {
					language_status = "1";
				}
				if (this.SPchecked == true) {
					video_status = "1"
				}
				this.$apiVipCentre.setStatus({
					text_status: text_status,
					language_status: language_status,
					video_status: video_status
				}).then((res) => {
					console.log(res.data.code)
				}).catch((error) => {})
			},

			// 一键开启关闭
			checkedAll() {
				if (this.TWchecked == true) {
					this.$apiVipCentre.setStatus({
						text_status: 0,
						language_status: 0,
						video_status: 0
					}).then((res) => {
						console.log(res.data.code)
					}).catch((error) => {})
					this.TWchecked = false;
					this.WYchecked = false;
					this.SPchecked = false;
				} else if (this.TWchecked == false) {
					this.$apiVipCentre.setStatus({
						text_status: 1,
						language_status: 1,
						video_status: 1
					}).then((res) => {
						console.log(res.data.code)
					}).catch((error) => {})
					this.TWchecked = true;
					this.WYchecked = true;
					this.SPchecked = true;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding-left: 15rpx;
		padding-right: 15rpx;
	}

	.p_text {
		line-height: 60rpx;
		border-bottom: 1px #f0f0f0 solid;
		margin: 30rpx 0rpx;
		padding: 0rpx 30rpx;
	}
</style>
